package xuegao.study.mall.common.api;


import com.github.pagehelper.PageInfo;
import lombok.Data;

import java.util.List;

@Data
public class CommonPage<T> {

    private Integer pageNum;

    private Integer pageSize;

    private Integer totalPage;
    // 暂时先把total改为Integer,要不拦截器将后台返回给前台的Long类型统一转换为String,分页插件接收total为string类型有问题
    private Integer total;

    private List<T> list;

    public static <T> CommonPage<T> restPage(List<T> list) {
        CommonPage<T> result = new CommonPage<T>();
        PageInfo<T> pageInfo = new PageInfo<T>(list);
        result.setTotalPage(pageInfo.getPages());
        result.setPageNum(pageInfo.getPageNum());
        result.setPageSize(pageInfo.getPageSize());
        long total= pageInfo.getTotal();
        result.setTotal((int)total);
        result.setList(pageInfo.getList());
        return result;
    }

}
